[Bug]: connection was closed in the middle of operation

Repo: · Issue: #377 Status: Open · Priority: P2 Assignee: Unassigned Labels: bug

Description

Steps to reproduce

Caused by https://twill-network.slack.com/archives/C07TPN6FCBX/p1750689325717899. Probably the same as https://github.com/Twill-AI/business-data/issues/63.

Not clear how to reproduce. Alerts happened only June 22 (2025-06-22 19:08:36.914) and June 23 (few occurrences starting at 2025-06-23 04:07:17.582 and finishing at 2025-06-23 14:33:33.158).

Expected behavior

No issues about db connections

Actual behavior

Logs:

2025-06-23 12:55:14.802|ERROR|Twllpymnts|fastapi_utils:164|GET http://staging.twillai.com/api/v1/home Unhandled exception: connection was closed in the middle of operation
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/asyncpg/pool.py", line 226, in release
    self._con.terminate()
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'terminate'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/app/core/fastapi_utils.py", line 122, in run_route_handler
    response = await dependant.call(**values)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/api/home_router.py", line 165, in home
    await Folder.select()
  Fi

## Implementation Notes
_Dash adds notes here while working_

## Related
_Link to people, meetings, dependent tickets_